package com.serviceprovider.business.module.order.model;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.order.valueobjects.OrderAttributeVO;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.List;

public class OrderAttribute {
    private OrderAttributeType type     = OrderAttributeType.STRING;
    private List<String>       enumList = new ArrayList<String>();
    private Integer            id;
    private boolean            isActive;
    private String             name;

    public OrderAttribute() {}

    public OrderAttribute(OrderAttributeVO orderAttribute) {
        this.setActive(orderAttribute.isActive());
        this.setId(orderAttribute.getId());
        this.setName(orderAttribute.getName());
        this.setType(orderAttribute.getType());
        enumList.clear();
        enumList.addAll(orderAttribute.getEnumList());
    }

    @Override
    public boolean equals(Object obj) {
        if ((obj == null) ||!(obj instanceof OrderAttribute)) {
            return false;
        }

        OrderAttribute b  = (OrderAttribute) obj;
        boolean        eq = ((id == null) && (b.id == null)) || ((id != null) && id.equals(b.id));

        if (!eq) {
            return false;
        }

        eq = ((name == null) && (b.name == null)) || ((name != null) && name.equals(b.name));

        if (!eq) {
            return false;
        }

        if (type == b.type) {
            return false;
        }

        eq = ((enumList == null) && (b.enumList == null)) || ((enumList != null) && enumList.equals(b.enumList));

        if (!eq) {
            return false;
        }

        if (isActive != b.isActive) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int prime  = 31;
        int result = 1;

        result = prime * result + ((id == null)
                                   ? 0
                                   : id.hashCode());
        result = prime * result + ((name == null)
                                   ? 0
                                   : name.hashCode());
        result = prime * result + ((type == null)
                                   ? 0
                                   : type.hashCode());
        result = prime * result + ((enumList == null)
                                   ? 0
                                   : enumList.hashCode());
        result = prime * result + ((isActive == false)
                                   ? 0
                                   : 1);

        return result;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public OrderAttributeType getType() {
        return type;
    }

    public void setType(OrderAttributeType type) {
        this.type = type;
    }

    public List<String> getEnumList() {
        return enumList;
    }

    public void setEnumList(List<String> enumList) {
        this.enumList = enumList;
    }

    public boolean isActive() {
        return isActive;
    }

    public void setActive(boolean active) {
        isActive = active;
    }
}



